﻿Public Class DRGDILIST
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub queryDrgdilistGrid()
        Dim objQueryDrgdilist As New DRGDILISTCLASS
        Dim dt As DataTable = connect.GetTable(objQueryDrgdilist.selectDrgdilist_)
        drgdilistGrid.PrimaryGrid.DataSource = dt
    End Sub

    Private Sub filterOnset()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(onsetid AS CHAR(6)) AS ONSETID, osname FROM drgdionset WHERE status = '1'"
        s = New FILTERCLASS(ONSETIDTxt, sql, "รหัสความต่อเนื่อง,ความต่อเนื่อง", "80,200", "1,1", "1,1")
        's.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Private Sub filterDrug1()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(`drgcode` AS CHAR(6)) AS DRGCODE, `tradename`, `genericname` FROM drugitem WHERE `status` = '1'"
        s = New FILTERCLASS(PRDCODEMTxt, sql, "รหัสยา,ชื่อทางการค้า,ชื่อสามัญ", "80,200,200", "1,1,1", "1,1,1")
        's.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Private Sub filterDrug2()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(`drgcode` AS CHAR(6)) AS DRGCODE, `tradename`, `genericname` FROM drugitem WHERE `status` = '1' AND `drgcode` <> '" & PRDCODEMTxt.Tag & "'"
        s = New FILTERCLASS(PRDCODENTxt, sql, "รหัสบัญชียา,ชื่อทางการค้า,ชื่อสามัญ", "80,200,200", "1,1,1", "1,1,1")
        's.SetShowInDown = False
        s.SetShowBorder = True
    End Sub



    Private Sub DRGDILIST_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryDrgdilistGrid()
        filterOnset()
        filterDrug1()
        filterDrug2()

        DesignForm(Me)
        DesignGrid(drgdilistGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub clearForm()
        LSTIDTxt.Clear()
        ONSETIDTxt.Clear()
        PRDCODEMTxt.Clear()
        PRDCODENTxt.Clear()
        EFFECTTxt.Clear()
        TIME_SAFETxt.Clear()
        SP_PAYChk.Checked = False
        STATUSChk.Checked = False
    End Sub

    Private Sub PRDCODEMTxt_TextChanged(sender As Object, e As EventArgs) Handles PRDCODEMTxt.TextChanged
        filterDrug2()
    End Sub

    Private Sub PRDCODENTxt_TextChanged(sender As Object, e As EventArgs) Handles PRDCODENTxt.TextChanged
        filterDrug1()
    End Sub

    Private Sub ONSETIDTxt_Click(sender As Object, e As EventArgs) Handles ONSETIDTxt.Click
        ONSETIDTxt.Clear()
    End Sub

    Private Sub drgdilistGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles drgdilistGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสยาที่เกิดอันตรกิริยา").Value() IsNot DBNull.Value Then
            LSTIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสยาที่เกิดอันตรกิริยา").Value()
        Else
            LSTIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสระยะเวลาที่ยามีผลต่อกัน").Value() IsNot DBNull.Value Then
            ONSETIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสระยะเวลาที่ยามีผลต่อกัน").Value()
            ONSETIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ระยะเวลาที่ยามีผลต่อกัน").Value()
        Else
            ONSETIDTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์หลัก").Value() IsNot DBNull.Value Then
            Dim objConvertDRGCODEtoPRDCODE As New GETPRDFROMDRG
            PRDCODEMTxt.Tag = objConvertDRGCODEtoPRDCODE.getDRGCODE(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์หลัก").Value())
            PRDCODEMTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อผลิตภัณฑ์หลัก").Value()
        Else
            PRDCODEMTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์รอง").Value() IsNot DBNull.Value Then
            Dim objConvertDRGCODEtoPRDCODE As New GETPRDFROMDRG
            PRDCODENTxt.Tag = objConvertDRGCODEtoPRDCODE.getDRGCODE(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์รอง").Value())
            PRDCODENTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อผลิตภัณฑ์รอง").Value()
        Else
            PRDCODENTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ผลและการจัดการ").Value() IsNot DBNull.Value Then
            EFFECTTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ผลและการจัดการ").Value()
        Else
            EFFECTTxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ระยะเวลาที่ไม่มีผลต่อกัน(วัน)").Value() IsNot DBNull.Value Then
            TIME_SAFETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ระยะเวลาที่ไม่มีผลต่อกัน(วัน)").Value()
        Else
            TIME_SAFETxt.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะห้ามจ่ายยา").Value() = True Then
            SP_PAYChk.Checked = True
        Else
            SP_PAYChk.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            STATUSChk.Checked = True
        Else
            STATUSChk.Checked = False
        End If

        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
                objChkboxUpdate.clickChkboxUpdate("drgdilist", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะห้ามจ่ายยา").Value(), "SP_PAY", "LSTID", LSTIDTxt.Text)
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If

        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
                objChkboxUpdate.clickChkboxUpdate("drgdilist", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "LSTID", LSTIDTxt.Text)
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub addDrgug_Click(sender As Object, e As EventArgs) Handles addDrgug.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If ONSETIDTxt.Text.Length.ToString > 0 And PRDCODEMTxt.Text.Length.ToString > 0 And PRDCODENTxt.Text.Length.ToString > 0 And TIME_SAFETxt.Text.Length.ToString > 0 Then
                    Dim objInsertData As New DRGDILISTCLASS
                    objInsertData.ONSETID_ = ONSETIDTxt.Tag

                    Dim objConvertDRGCODEtoPRDCODE As New GETPRDFROMDRG
                    objInsertData.PRDCODEM_ = objConvertDRGCODEtoPRDCODE.getPRDCODE(PRDCODEMTxt.Tag)

                    Dim objConvertDRGCODEtoPRDCODE2 As New GETPRDFROMDRG
                    objInsertData.PRDCODEN_ = objConvertDRGCODEtoPRDCODE2.getPRDCODE(PRDCODENTxt.Tag)

                    objInsertData.EFFECT_ = EFFECTTxt.Text
                    objInsertData.SP_PAY_ = SP_PAYChk.Checked
                    objInsertData.TIME_SAFE_ = TIME_SAFETxt.Text
                    objInsertData.STATUS_ = STATUSChk.Checked

                    If objInsertData.insertDrgdilist() = True Then
                        MsgBox("ท่านได้ทำการเพิ่มตัวยาที่ออกฤทธิ์ต้านกันเรียบร้อยแล้ว")
                        queryDrgdilistGrid()
                        clearForm()
                    End If
                Else
                    MsgBox("โปรดกรุณาระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editDrgug_Click(sender As Object, e As EventArgs) Handles editDrgug.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If LSTIDTxt.Text.Length.ToString > 0 And ONSETIDTxt.Text.Length.ToString > 0 And PRDCODEMTxt.Text.Length.ToString > 0 And PRDCODENTxt.Text.Length.ToString > 0 And TIME_SAFETxt.Text.Length.ToString > 0 Then
                    Dim objEditData As New DRGDILISTCLASS
                    objEditData.LSTID_ = LSTIDTxt.Text
                    objEditData.ONSETID_ = ONSETIDTxt.Tag

                    Dim objConvertDRGCODEtoPRDCODE As New GETPRDFROMDRG
                    objEditData.PRDCODEM_ = objConvertDRGCODEtoPRDCODE.getPRDCODE(PRDCODEMTxt.Tag)

                    Dim objConvertDRGCODEtoPRDCODE2 As New GETPRDFROMDRG
                    objEditData.PRDCODEN_ = objConvertDRGCODEtoPRDCODE2.getPRDCODE(PRDCODENTxt.Tag)

                    objEditData.EFFECT_ = EFFECTTxt.Text
                    objEditData.SP_PAY_ = SP_PAYChk.Checked
                    objEditData.TIME_SAFE_ = TIME_SAFETxt.Text
                    objEditData.STATUS_ = STATUSChk.Checked

                    If objEditData.editdrgdionset() = True Then
                        MsgBox("ท่านได้ทำการแก้ไขข้อมูลตัวยาที่ออกฤทธิ์ต้านกันเรียบร้อยแล้ว")
                        queryDrgdilistGrid()
                        clearForm()
                    End If
                Else
                    MsgBox("โปรดกรุณาระบุข้อมูลให้ครบถ้วน")
                End If

            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("drgdilist")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("drgdilist")
        nextform.ShowDialog()
    End Sub

   
   
End Class